<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%
	String userId = request.getParameter("userId");
%>
<script type="text/javascript">

	$(function(){
		//加载两个要使用json分页的组件
        loadGird("frm", 1);
	})
		
	//对第一个frm的回调函数, 方法的命名规则为callback_+表单id	
	var callback_frm = function(rows, frm) {
       $.each(rows, function(i, n){
    	   var row = $("#"+frm+" .template").clone().removeClass("template");
           row.find(".klId").attr("value",n.id);
       	   row.find(".klName").text(n.name);
           row.find(".klRemarks").text(n.remarks);
           row.attr("id","ready"+i);//改变绑定好数据的行的id
           row.attr("class","tr_nbw");
           row.appendTo("#"+frm+" .grid");//添加到模板的容器中
       });   
	}
	
	var delrolesforuser = function(){
		var options = {
		type: 'POST',
		async: false,
		dataType: 'content-type',
		success: function(msg) {
			alert("删除成功！");
			document.location.reload();
		}
		}
		if(confirm('您确认要删除吗？')){
			//提交form
			document.getElementById("frm").action="<%=path %>/sys/user/delroles";
			$('#frm').ajaxSubmit(options);
		}
	}
	
	var  addRolesForUser = function(){
		selMultiRole('roles','rolenames')
	    var options = {
			type: 'POST',
			async: false,
			dataType: 'content-type',
			success: function(msg) {
				alert("添加成功！");
				window.location.reload();
			}
		}
		if(document.getElementById("roles").value!=""){
			document.getElementById("frm").action="<%=path %>/sys/user/addroles";
			$('#frm').ajaxSubmit(options);
			document.getElementById("frm").action="<%=path %>/sys/user/showroles";
		}
	}
	function goback(){
		window.location = "<%=path%>/sys/user/get/userList";
	}
</script>
<!-- 测试的表单1 frm1 请求json的action请求必须填写 -->
<form name="frm" method="post"
	action="<%=path %>/sys/user/showroles" id="frm">
	<input type="hidden" name="roles" id="roles" >
	<input type="hidden" name="rolenames" id="rolenames" >
	<input type="hidden" name="userId" value="<%=userId %>" >
	<table><tr><td height="2px"></td></tr></table>
	&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="#" onclick="addRolesForUser()" >添加角色</a>&nbsp;|&nbsp;
		<a href="#" onclick="delrolesforuser()" >移除角色</a>&nbsp;|&nbsp;
		<a href="#" onclick="goback()" >返回</a>
	<center>
	<table><tr><td height="2px"></td></tr></table>
	<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
		<thead class="th_nbw">
			<tr>
				<td width="40px">
					<input type="checkbox" class="allCheck" />
				</td>
				<td>
					角色名称
				</td>
				<td>
					备注
				</td>
			</tr>
		</thead>
		<tbody>
			<tr class="template klId">
				<td width="40px" class="idCheck">
					<input type="checkbox" name="chk" class="klId" />
				</td>
				<td class="klName niceTable-left"></td>
				<td class="klRemarks niceTable-left"></td>
			</tr>
		</tbody>
		<tfoot>
			<tr>
				<td style="border-right: none">
					<img class="loading"
						src="<%=imgPath %>/large-loading.gif" width="20px"
						class="hidden" />
				</td>
				<td colspan="4" style="border-left: none" class="txtRight">
					<span class="pagediv"></span>
				</td>
			</tr>
		</tfoot>
	</table>
	</center>
</form>